
public class Demo65 {

public int[] elem;
public int usesize;

    public void Demo65(int[] elem) {
        this.elem = new int[10];
    }
    public void initElem(int[] array){
        for (int i = 0; i < array.length; i++) {
            elem[i] =array[i];
            usesize++;
        }
    }
    public void createHeap(){
        for (int parent=  (usesize-1-1)/2; parent>=0;parent--) {
            siftDown(parent,usesize);
        }
    }
    private void siftDown(int parent,int len){
        int child = parent*2+1;
        while(child<len){
            if(child+1<len && elem[child] < elem[child+1]){
                child=child+1;
            }
            if(elem[child] > elem[parent]){
                int tem = elem[parent];
                elem[parent] = elem[child];
                elem[child] = tem;
                parent = child;
                child =parent*2 +1;
            }
            else{
                break;
            }
        }
    }

}
